<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ include file="/includes/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加用户</title>
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/common.css" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="<%=request.getContextPath()%>/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
	var type = '${type}';
	if(type=='add'){
		alert("添加学生成功！");
	}else if(type == "edit"){
		alert("编辑学生成功！");
		window.location.href = "listStudent.action";
	}
	function loadInstitute(){
		var action = "listInstitueJson.action";
		$("#instituteId").find("option").remove();
		$("#instituteId").append('<option value="">---请选择学院---</option>');
		var institudeId = "${student.clazz.department.institute.id}";
		$.getJSON(action,function(data){
			var json = eval(data);
			$.each(json,function(i,n){
				if(institudeId == json[i].id){
					$("#instituteId").append('<option selected value='+json[i].id+'>'+json[i].name+'</option>');
				}else{
					$("#instituteId").append('<option value='+json[i].id+'>'+json[i].name+'</option>');
				}
			}) 
		});
		if(institudeId!=""){
			selDepartment();
		}
	}
	function selDepartment(){
		var departmentId = "${student.clazz.department.id}";
		var id = "${student.clazz.department.institute.id}";
		if(id == ""){
			id = $("#instituteId").val();		
		}
		var action = "listDepartmentJson.action?institute.id="+id;
		$.getJSON(action,function(data){
			var json = eval(data);
			$.each(json,function(i,n){
				if(departmentId==json[i].id){
					$("#departmentId").append('<option selected value='+json[i].id+'>'+json[i].name+'</option>');
				}else{
					$("#departmentId").append('<option value='+json[i].id+'>'+json[i].name+'</option>');
				}
			})
		})
		if(departmentId!=""){
			selClass();
		}
	}
	
	function selClass(){
		var clazzId = "${student.clazz.id}";
		var id = "${student.clazz.department.id}";
		if(id == ""){
			id = $("#departmentId").val();			
		}
		var action = "listClazzJson.action?department.id="+id;
		$.getJSON(action,function(data){
			var json = eval(data);
			$.each(json,function(i,n){
				if(clazzId==json[i].id){
					$("#clazz").append('<option selected value='+json[i].id+'>'+json[i].name+'</option>');
				}else{
					$("#clazz").append('<option value='+json[i].id+'>'+json[i].name+'</option>');
				}
			})
		})
	}
</script>
</head>
	<body onload="loadInstitute();">
		<div id="man_zone">
		<form action="saveStudent.action" method="post" id="form1" >
		<input type="hidden"  name="student.id" value="${student.id}"/>
		<input type="hidden"  name="student.version" value="${student.version}"/>
		 <table class="table_style" border="0" align="center"  cellpadding="3" cellspacing="1" width="800px">
		   	<tr>
		   		<td class="left_title_1">学号:</td>
		   		<td>
		   		<input type="text" id="student.stuNo" name="student.stuNo" value="${student.stuNo}" <s:if test="student.id !=null">readOnly</s:if>/>
		   		<s:if test="hasFieldErrors() && fieldErrors.get('student.stuNo') != null">
					<s:fielderror><s:param>student.stuNo</s:param></s:fielderror>
				</s:if>
				<s:actionerror/>
		   		</td>
		   		<td class="left_title_1">姓名:</td>
		   		<td>
		   		<input type="text" id="student.name" name="student.name" value="${student.name}"/>
		   		<s:if test="hasFieldErrors() && fieldErrors.get('student.name') != null">
					<s:fielderror><s:param>student.name</s:param></s:fielderror>
				</s:if>
		   		</td>	
		   	</tr>
		   	<tr>
		   		<td class="left_title_1">电话:</td>
		   		<td>
		   		<input type="text" id="student.tel" name="student.tel" value="${student.tel}"/>
		   		<s:if test="hasFieldErrors() && fieldErrors.get('student.tel') != null">
					<s:fielderror><s:param>student.tel</s:param></s:fielderror>
				</s:if>
		   		</td>
		   		<td class="left_title_1">手机:</td>
		   		<td>
		   		<input type="text" id="student.phone" name="student.phone" value="${student.phone}"/>
		   		<s:if test="hasFieldErrors() && fieldErrors.get('student.phone') != null">
					<s:fielderror><s:param>student.phone</s:param></s:fielderror>
				</s:if>
		   		</td>	
		   	</tr>
		   	<tr>
		   		<td class="left_title_1">身份证:</td>
		   		<td>
		   		<input type="text" id="student.idcard" name="student.idcard" value="${student.idcard}"/>
		   		<s:if test="hasFieldErrors() && fieldErrors.get('student.idcard') != null">
					<s:fielderror><s:param>student.idcard</s:param></s:fielderror>
				</s:if>
		   		</td>	
		   		<td class="left_title_1">生日:</td>
		   		<td>
		   		<input type="text" id="student.birthdate" name="student.birthdate" value="<s:date name="student.birthdate" format="yyyy-MM-dd"/>" onClick="WdatePicker()" readonly/>
		   		<s:if test="hasFieldErrors() && fieldErrors.get('student.birthdate') != null">
					<s:fielderror><s:param>student.birthdate</s:param></s:fielderror>
				</s:if>
		   		</td>	
		   	</tr>
		   	<tr>
		   		<td class="left_title_1">性别:</td>
		   		<td>
		   		 <input name="student.sex" type="radio" value="0" checked="checked" />男 
				 <input type="radio" name="student.sex" value="1"/>女
				 <s:if test="hasFieldErrors() && fieldErrors.get('student.sex') != null">
					<s:fielderror><s:param>student.sex</s:param></s:fielderror>
				</s:if>
		   		</td>	
		   		<td class="left_title_1">密码:</td>
		   		<td>
		   		<input type="text" id="student.password" name="student.password" value="${student.password}"/>
		   		<s:if test="hasFieldErrors() && fieldErrors.get('student.password') != null">
					<s:fielderror><s:param>student.password</s:param></s:fielderror>
				</s:if>
		   		</td>	
		   	</tr>
		   	<tr>
		   		<td class="left_title_1">状态:</td>
		   		<td>
					<select name="student.status">
						<option>在读</option>
						<option>已毕业</option>
						<option>退学</option>
						<option>开除</option>
					</select>
		   		</td>	
		   		<td class="left_title_1">邮件:</td>
		   		<td>
		   		<input type="text" id="student.email" name="student.email" value="${student.email}"/>
		   		<s:if test="hasFieldErrors() && fieldErrors.get('student.email') != null">
					<s:fielderror><s:param>student.email</s:param></s:fielderror>
				</s:if>
		   		</td>	
		   	</tr>
	   	 	<tr>
	   		<td class="left_title_1">班级:</td>
	   		<td colspan="3">
			学院：<select id="instituteId" onchange="selDepartment();">
					<option>---请选择学院---</option>
					<s:iterator value="institutes">
						<option value="${id}">${name}</option>
					</s:iterator>
				</select>
			专业：<select id="departmentId" onchange="selClass();">
					<option>---请选择系---</option>
				</select>
			班级：<select id="clazz" name="student.clazz.id">
					<option>---请选择班级---</option>
				</select>
	   		</td>	
		   	</tr>
		   	<tr>
		   	<td class="left_title_1">地址:</td>
		   		<td colspan="3">
		   		<input type="text" id="student.address" name="student.address" value="${student.address}" style="width:400px;"/>
		   		<s:if test="hasFieldErrors() && fieldErrors.get('student.address') != null">
					<s:fielderror><s:param>student.address</s:param></s:fielderror>
				</s:if>
		   		</td>	
		   	</tr>
        <tr>   	
        </tr>
		  </table>
		  <table class="table_style" border="0" align="center"  cellpadding="3" cellspacing="0">
       		<tr>
         <td>
          <input type="submit" value="提交" />
          <span class="sub_sp">&nbsp;</span>
          <s:reset value="重置"/>  
         </td>
       </tr>
	</table>
		</form>
		</div>
	</body>
</html>